package com.leetcode.merci.lc557;

/**
 * Created by bowen on 2017/7/24.
 */
public class Solution {
    public String reverseWords(String s) {
        char[] words=s.toCharArray();
        int j=0;
        for(int i=0;i<words.length;i++){
            if(words[i]==' '){
                revert(words,j,i);
                j=i+1;
            }
        }
        revert(words,j,words.length-1);
        return new String(words);
    }
    public void revert(char[] s,int a,int b){
        while(a<b){
            char tmp=s[a];
            s[a]=s[b];
            s[b]=tmp;
            a++;
            b--;
        }
    }
}